package com.docker.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.docker.demo.model.ResutlDTO;
import com.docker.demo.service.AdverInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @describetion:
 * @author: Administrator
 * @createTime: 2018/12/19/0019.
 */
@RestController
@RequestMapping(value = "/api/v1",produces = "application/json;charset=utf-8")
@Api(value = "广告控制器",description = "广告控制器")
public class AdverInfoController {
    private final static Logger logger = LoggerFactory.getLogger(AdverInfoController.class);

    @Autowired
    private AdverInfoService adverInfoService;

    @ApiOperation(value = "通过id获取广告信息")
    @GetMapping(value = "/getAdverInfo/{id}")
    public ResutlDTO test(@ApiParam(name = "id",value = "广告主键",required = true)@PathVariable(value = "id") Integer id){
        logger.info("--/getAdverInfo/{id}-------:"+id);
        ResutlDTO resutlDTO = new ResutlDTO();
        try {
            Assert.notNull(id,"id不能为空");
            Map<String, Object> map = adverInfoService.findOneById(id);
            /*封装结果*/
            resutlDTO.setStatus(HttpStatus.OK.value());
            resutlDTO.setData(map);
        }catch (Exception e){
            logger.error("异常信息："+e);
            resutlDTO.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            resutlDTO.setMessage(e.getMessage());
        }
        logger.info("/getAdverInfo/{id}返回结果："+ JSONObject.toJSONString(resutlDTO));
        return resutlDTO;
    }
}
